package com.example.controller.web;

import com.example.common.Result;
import com.example.entity.Article;
import com.example.service.PopularService;
import com.example.vo.CategoryPopularVO;
import com.example.vo.TagPopularVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 热门内容控制器
 */
@Slf4j
@RestController("webPopularController")
public class PopularController {
    
    @Resource
    private PopularService popularService;
    
    /**
     * 获取热门文章
     * 
     * @param params 包含排序参数 sortBy: favorites(收藏数), likes(点赞数), comments(评论数)
     * @return 热门文章列表
     */
    @PostMapping("/article/popular")
    public Result<List<Article>> getPopularArticles(@RequestBody Map<String, String> params) {
        log.info("获取热门文章请求，参数: {}", params);
        
        String sortBy = params.getOrDefault("sortBy", "favorites");
        List<Article> articles = popularService.getPopularArticles(sortBy);
        
        return Result.success(articles);
    }
    
    /**
     * 获取热门标签
     * 
     * @return 热门标签列表
     */
    @PostMapping("/tag/popular")
    public Result<List<TagPopularVO>> getPopularTags() {
        log.info("获取热门标签请求");
        
        List<TagPopularVO> tags = popularService.getPopularTags();
        
        return Result.success(tags);
    }
    
    /**
     * 获取热门分类
     * 
     * @return 热门分类列表
     */
    @PostMapping("/category/popular")
    public Result<List<CategoryPopularVO>> getPopularCategories() {
        log.info("获取热门分类请求");
        
        List<CategoryPopularVO> categories = popularService.getPopularCategories();
        
        return Result.success(categories);
    }
} 